<html>
<head><meta charset="utf-8"><title>Adding Symbolic Compilation · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html">Adding Symbolic Compilation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213223301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213223301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nyms <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213223301">(Oct 13 2020 at 22:10)</a>:</h4>
<p>Hi all, new here, and I'm working on adding a custom LLVM pass for symbolizing function arguments in binaries using <a href="https://github.com/eurecom-s3/symcc">SymCC</a>.</p>
<p>I dug into the docs in the <a href="https://rustc-dev-guide.rust-lang.org/backend/debugging.html#compiler-options-to-know-and-love">rustc-dev-guide</a> for running custom LLVM passes, but it isn't clear how best to load a custom pass from a module. Any advice on the best place to load/run the <code>symbolize</code> pass, and subsequently compile <code>alloc/core/std</code> with symbolic arguments?</p>
<p>Basically, the end-goal is to end up with a wrapped <code>rustc</code> similar to the wrapper around <code>clang</code> that <code>symcc/sym++</code> uses, and then use the wrapped <code>rustc</code>to compile crates with symbolic instrumentation.</p>
<p>Thanks in advance for any advice</p>



<a name="213241638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213241638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nyms <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213241638">(Oct 14 2020 at 02:58)</a>:</h4>
<p>follow-up: found the API for <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_codegen_llvm/src/back/write.rs#L454">LLVM backend</a> opt passes. Is this a good place to add a custom pass? Are there less invasive ways to add a custom pass? Apologies if these are dumb questions. Got some success adding symbolic instrumentation using <code>opt</code> and <code>llc</code>, but was hoping for a solution that could be run with something like <code>cargo sym build/run/etc</code>.</p>



<a name="213372977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213372977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213372977">(Oct 15 2020 at 02:10)</a>:</h4>
<p>This is absolutely a reasonable question and a reasonable place to ask it, unfortunately I don't have much to say except that I saw a similar thread recently about adding a custom LLVM pass in a non-invasive "plug-in" fashion and based on the conversation that resulted, it seems that no, there's not really a better way.</p>
<p><span class="user-mention silent" data-user-id="138448">cuviper</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/llvm.20obfuscation/near/213052485">said</a>:</p>
<blockquote>
<p>It would be great to figure that out though... Nick Clifton was looking at adding <code>annobin</code> support to LLVM as a plug-in pass, and we'd love to load that for rustc too</p>
</blockquote>



<a name="213514609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213514609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nyms <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213514609">(Oct 16 2020 at 03:24)</a>:</h4>
<p>Thanks, will keep playing around with stuff. Looking at <code>miri</code>, <code>cargo-fuzz</code> (and now <code>annobin</code> :) for inspiration on adding passes. SymCC hooks the std library for C (libc++) with instrumentation, and wraps <code>clang</code> to add instrumentation passes to other code under test. So, trying to figure out the build.</p>
<p>Right now I'm doing: (1) use <a href="http://build.rs">build.rs</a> to run SymCC build system,  (2) compile <code>alloc/core/std</code> to LLVM IR, (3) use <code>libSymbolize.so</code> (LLVM pass artifact) as opt pass, (4) compile to assembly with <code>llc</code>, (5) compile assembly to machine code with <code>cc</code> crate.</p>
<p>Still working on 2-5. Then, to get it working for code under test, either need a way to link the instrumented <code>alloc/core/std</code>, fully compile <code>rustc</code> with symbolic instrumentation, or something else entirely; not sure which yet.</p>
<p>Having a "plug-in" functionality would be awesome, and I'm down to help anyone already working on something like that (or begin work on it if not).</p>



<a name="213736340"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213736340" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213736340">(Oct 19 2020 at 01:47)</a>:</h4>
<p><a href="https://rustc-dev-guide.rust-lang.org/sanitizers.html">https://rustc-dev-guide.rust-lang.org/sanitizers.html</a><br>
Maybe the sanitizer instrumentation would help you with this?</p>



<a name="213965190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Adding%20Symbolic%20Compilation/near/213965190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Adding.20Symbolic.20Compilation.html#213965190">(Oct 20 2020 at 19:03)</a>:</h4>
<p>Ah, <a href="https://github.com/rust-lang/rust/issues/74705">#74705</a> covers a new pass manager being added recently, behind an unstable flag.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>